import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/components/app/app_ripple_button.dart';
import 'package:interview/config/app.enum.dart';
import 'package:interview/controller/navigation_controller.dart';
import 'package:interview/theme/app_colors.dart';

class MineSetting extends StatefulWidget {
  final AppColors theme;
  const MineSetting({super.key, required this.theme});

  @override
  State<MineSetting> createState() => _MineSettingState();
}

class _MineSettingState extends State<MineSetting> {
  final navigation = Get.find<NavigationController>();



  final List<Map<String, dynamic>> settingList = [
    {"path": "ic_mine_notes.png", "text": "单词朗读"},
    {"path": "ic_mine_ai.png", "text": "面通AI"},
    {"path": "ic_mine_invite.png", "text": "面试录音"},
    {"path": "ic_mine_file.png", "text": "意见反馈"},
    {"path": "ic_mine_info.png", "text": "线程任务"},
    {"path": "ic_mine_setting.png", "text": "系统设置"},
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: widget.theme.subjectMix1,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        children: List.generate(settingList.length, (index) {
          final item = settingList[index];
          return _settingItem(
            path: item["path"],
            text: item["text"],
            theme: widget.theme,
            onTap: () => _onSettingTap(item["text"]), // 添加点击事件
          );
        }),
      ),
    );
  }

  Widget _settingItem({
    required String path,
    required String text,
    required AppColors theme,
    required VoidCallback onTap,
  }) {
    return AppRippleButton(
      onTap: onTap,
      rippleRadius:BorderRadius.circular(8),
      borderRadius:BorderRadius.circular(8),
      backgroundColor: theme.subjectMix1!,
      splashColor:theme.contrastMix3!.withOpacity(0.2),
      highlightColor:theme.subjectMix1!.withOpacity(0.1),
      child: Container(
        padding: const EdgeInsets.symmetric(vertical: 16 , horizontal: 16),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Image.asset('${AppEnumAssets.basePath}$path', width: 16, height: 16),
                const SizedBox(width: 12),
                Text(
                  text,
                  style: TextStyle(
                    fontSize: 12,
                    fontWeight: FontWeight.w500,
                    color: theme.contrastMix3,
                  ),
                ),
              ],
            ),
            const Icon(Icons.keyboard_arrow_right, size: 16),
          ],
        ),
      ),
    );
  }



  void _onSettingTap(String text) {
    switch (text) {
      case "系统设置":
        navigation.push("/settingpage");
        break;
      case "面试录音":
        navigation.push("/recordpage");
        break;
      case "线程任务":
        navigation.push("/taskpage");
        break;
      default: return;
    }
  }
}
